﻿using System;

class Program
{
    static void Main()
    {
        
        //Bulls and Cows

        int secretNumber = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());

        int firstNumber = secretNumber / 1000;
        int secondNumber = (secretNumber / 100) % 10;
        int thirdNumber = (secretNumber / 10) % 10;
        int fourthNumber = secretNumber % 10;

        int combinations = (int)Math.Pow(2, b); // -1

        if (b == 4)
        {
            Console.WriteLine(secretNumber);
        }
        else if (b == 3 && c== 0)
        {
            for (int i = 1; i <= 9; i++)
            {
                

                Console.Write("{0}{1}{2}{3} ",firstNumber,secondNumber,thirdNumber,i);
                Console.Write("{0}{1}{2}{3} ", i, firstNumber, secondNumber, thirdNumber);
                Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, i, fourthNumber);
                Console.Write("{0}{1}{2}{3} ", firstNumber, i, thirdNumber, fourthNumber);
            }
        }
        else if (b == 3 && c == 1)
        {
            string newNumber = Convert.ToString(firstNumber) + Convert.ToString(secondNumber) +
                                Convert.ToString(thirdNumber) + Convert.ToString(c);
            Console.WriteLine(newNumber);
            Console.WriteLine();

            Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, thirdNumber, c);
            Console.Write("{0}{1}{2}{3} ", c, firstNumber, secondNumber, thirdNumber);
            Console.Write("{0}{1}{2}{3} ", firstNumber, secondNumber, c, fourthNumber);
            Console.Write("{0}{1}{2}{3} ", firstNumber, c, thirdNumber, fourthNumber);
        }
       
        
    }
}
